package com.cloudlinkscm.base.authcenter.dao;

import com.cloudlinkscm.base.authcenter.mapper.PublicResourceMapper;
import com.cloudlinkscm.base.authcenter.model.PublicResource;
import com.cloudlinkscm.loms.framework.dao.GenericBizDao;
import com.cloudlinkscm.loms.framework.dao.GenericDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.Collection;
import java.util.List;

/**
 * @author : tac
 * @date : 28/07/2017
 */
@Repository
public class PublicResourceDao extends GenericDao<PublicResource, String> {

	@Autowired
    public PublicResourceDao(PublicResourceMapper mapper) {
        super(mapper);
    }

    /**
     * 递归删除所有资源
     */
    public int deleteByPrimaryKeyRecursively(String id) {
        //todo::
        return 0;
    }

    public List<PublicResource> selectByPrimaryKeys(List<String> publicResourceIds) {
        //todo::
        return null;
    }

    public List<PublicResource> selectByPid(String pid) {
    	PublicResource resource = new PublicResource();
	    resource.setPid(pid);
    	return select(resource);
    }

    public List<PublicResource> selectByPids(Collection<String> pids) {
	    Example example = new Example(PublicResource.class);
	    example.createCriteria().andIn("pid", pids);

		return selectByExample(example);
    }

    public PublicResource selectByResourceKey(String resourceKey) {
    	PublicResource publicResource = new PublicResource();
    	publicResource.setResourceKey(resourceKey);
		return selectOne(publicResource);
    }

    public int updateByResourceKey(String resourceKey, PublicResource publicResource) {
	    Example example = new Example(PublicResource.class);
	    example.createCriteria().andEqualTo("resourceKey", resourceKey);

	    return updateByExampleSelective(publicResource, example);
    }

    public List<PublicResource> selectByIds(Collection<String> ids) {
	    Example example = new Example(PublicResource.class);
	    example.createCriteria().andIn("id", ids);
	    return selectByExample(example);
    }
}
